package com.czp.audit.action;

import com.czp.audit.model.AuditType;
import com.czp.audit.service.IAuditService;
import com.czp.framework.action.BaseActionSupport;
import com.czp.framework.exception.IServiceException;

/**
 * 【环 境】：J2SE 1.7
 * @author   柴志鹏	CHAIZP@GMAIL.COM
 * @version  version 1.0
 * @since    2014-11-13
 */
public class AuditAction extends BaseActionSupport {
	private static final long serialVersionUID = -3236616637698333620L;
	private IAuditService auditService;
	private AuditType at;
	
	/** 
	 * 【描 述】：查询审核类型信息
	 */
	public void queryAuditType() {
		try {
			AuditType at = new AuditType();
			at.setStart(Integer.parseInt(request.getParameter("start")));
			at.setLimit(Integer.parseInt(request.getParameter("limit")));
			at.setAuditType(request.getParameter("auditType"));
			this.responseOutPrint(auditService.queryAuditTypeList(at));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "queryAuditType", e);
		}
	}
	
	/** 
	 * 【描 述】：根据类型Id查询审核流程
	 */
	public void queryAuditProcessByTypeId() {
		try {
			int start = Integer.parseInt(request.getParameter("start"));
			int limit = Integer.parseInt(request.getParameter("limit"));
			String typeId = request.getParameter("typeId");
			responseOutPrint(
					auditService.queryAuditProcessByTypeId(typeId, start, limit));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "queryAuditProcess", e);
		}
	}
	
	/** 
	 * 【描 述】：重新排序审核流程
	 */
	public void sortProcess() {
		try {
			String json = request.getParameter("data");
			responseOutPrint(
					auditService.sortProcess(json));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "sortProcess", e);
		}
	}

	/** 
	 * 【描 述】："审核类型"增删改控制器
	 */
	public void auditTypeController() {
		try {
			int count = auditService.auditTypeController(at);
			responseOutPrint("{success: "+ count +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "auditTypeController", e);
		}
	}
	
	/** 
	 * 【描 述】："审核流程"增删改控制器
	 */
	public void auditProcessController() {
		try {
			String typeId = request.getParameter("typeId");
			String data = request.getParameter("data");
			int count = auditService.auditProcessController(typeId, data);
			responseOutPrint("{success: "+count+"}");
		} catch(Exception e) {
			throw new IServiceException(getClass()+ "auditProcessController", e);
		}
	}
	
	/** 
	 * 【描 述】：获取"可选"审核流程
	 */
	public void getOptionallyProcess() {
		try {
			String typeId = request.getParameter("typeId");
			responseOutPrint(
					auditService.getOptionallyProcess(typeId));
		} catch(Exception e) {
			throw new IServiceException(getClass()+ "getOptionallyProcess", e);
		}
	}
	
	/** 
	 * 【描 述】：获取"已选"审核流程
	 */
	public void getSelectedProcess() {
		try {
			String typeId = request.getParameter("typeId");
			responseOutPrint(auditService.getSelectedProcess(typeId));
		} catch(Exception e) {
			throw new IServiceException(getClass()+ "getSelectedProcess", e);
		}
	}

	/**
	 * 获取 auditService
	 * @return 返回 auditService
	 */
	public IAuditService getAuditService() {
		return auditService;
	}

	/**
	 * 设置 auditService
	 * @param 对auditService进行赋值
	 */
	public void setAuditService(IAuditService auditService) {
		this.auditService = auditService;
	}

	/**
	 * 获取 at
	 * @return 返回 at
	 */
	public AuditType getAt() {
		return at;
	}

	/**
	 * 设置 at
	 * @param 对at进行赋值
	 */
	public void setAt(AuditType at) {
		this.at = at;
	}
	
	public void testProcess() {
		try {
			String yewuid = request.getParameter("id");
			System.out.println(yewuid);
			responseOutPrint(auditService.testProcess(yewuid));
		} catch (Exception e) {
			throw new IServiceException(getClass()+ "testProcess", e);
		}
	}
	
	
}
